package com.mall.web.controller.system;

import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.framework.shiro.service.SysRegisterService;
import com.mall.system.domain.entity.SysUser;
import com.mall.system.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 注册验证
 *
 * Created by zhonglin on 2020/4/8.
 */
@Controller
public class SysRegisterController
    extends BaseController {

  @Autowired
  private SysRegisterService registerService;

  @Autowired
  private SysConfigService configService;

  @GetMapping("/register")
  public String register() {

    return "register";
  }

  @PostMapping("/register")
  @ResponseBody
  public AjaxResult ajaxRegister(SysUser user) {

    if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
      return error("当前系统没有开启注册功能！");
    }
    String msg = registerService.register(user);
    return StringUtils.isEmpty(msg)
        ? success()
        : error(msg);
  }

}
